package cn.zhaoyuening.schoolmates.web.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.zhaoyuening.schoolmates.domain.Photos;
import cn.zhaoyuening.schoolmates.service.PhotosService;

@RestController
@RequestMapping("admin")
public class AdminPhotosController {
	@Autowired
	private PhotosService photosService;
	
	@RequestMapping(value="photos",method=RequestMethod.POST)
	public String addPhotos(@ModelAttribute Photos photos){
		photosService.save(photos);
		return "success";
	}
	
	@RequestMapping(value="photos",method=RequestMethod.PUT)
	public String editPhotos(@ModelAttribute Photos photos){
		if(photos.getId()==null){
			return "fail";
		}
		photosService.addOrEdit(photos);
		return "success";
	}
	@RequestMapping(value="photos",method=RequestMethod.DELETE)
	public String editPhotos(Long id){
		if(id==null){
			return "fail";
		}
		Photos photos = new Photos();
		photos.setId(id);
		photosService.delete(photos);
		return "success";
	}
	
	@RequestMapping(value="photos/order",method=RequestMethod.PUT)
	public String updateOrder(Long id,Integer order){
		photosService.updateOrder(id, order);
		return "success";
	}
	
}
